import { _decorator, Component, Node, Sprite,Color } from 'cc';
import { Healthy } from './Healthy';
const { ccclass, property } = _decorator;

@ccclass('ColorHp')
export class ColorHp extends Component {
    sp:Sprite =null;
    start() {
        this.sp =this.getComponent(Sprite);
        this.node.on("HURT",this.hurt,this);
        this.changeColor(this.getComponent(Healthy).curHp);
    }
    protected onDestroy(): void {
        
        this.node.off("HURT",this.hurt,this);
    }
    hurt(hp:number){
        this.changeColor(hp);
    }
    
    changeColor(hp:number){
        if(hp>=12){
            this.sp.color = Color.YELLOW.clone();
        }else if(hp<12 &&hp >=6){
            this.sp.color=Color.GREEN.clone();
        }else {
            this.sp.color=Color.WHITE.clone();
        }
    }

    update(deltaTime: number) {
        
    }
}


